package com.superzqb.asus.superzqbFragment.superzqbSave;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.superzqb.asus.superzqb.R;
import com.superzqb.asus.superzqbUtil.RoundImageView;

import static com.superzqb.asus.superzqbFragment.superzqbSave.AddAim.buyFlag;
import static com.superzqb.asus.superzqbFragment.superzqbSave.AddAim.myAimFlag;
import static com.superzqb.asus.superzqbFragment.superzqbSave.AddAim.saveFlag;
import static com.superzqb.asus.superzqbFragment.superzqbSave.AddAim.tripFlag;

public class SubmitMyAim extends Activity implements View.OnClickListener{
    private Context context;
    private Intent intent;
    private TextView title,submit;
    private EditText wantBuy,toBuy,toBuyDay,toSavePer;
    private ImageView back;
    private ArrayAdapter<String> timeAdapter;
    private String[] timeItems;
    private Spinner timeArray;
    private RoundImageView pic;
    private static int  type;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.submit_my_aim);
        initView();
    }

    private void initView() {
        context=SubmitMyAim.this;
        intent=getIntent();
        title=(TextView)findViewById(R.id.title);
        type=intent.getIntExtra("flag",buyFlag);
        pic=(RoundImageView) findViewById(R.id.pic);
        chooseTitle(type);

        back=(ImageView)findViewById(R.id.back);
        wantBuy=(EditText) findViewById(R.id.wantBuy);
        toBuy=(EditText) findViewById(R.id.toBuy);
        toBuyDay=(EditText) findViewById(R.id.toBuyDay);
        toSavePer=(EditText) findViewById(R.id.toSavePer);


        submit=(TextView) findViewById(R.id.submit);
        timeArray=(Spinner)findViewById(R.id.time_array);
        timeItems = getResources().getStringArray(R.array.time_array);
        timeAdapter=new ArrayAdapter<>(this,R.layout.simple_spinner_item, timeItems);
        timeAdapter.setDropDownViewResource(R.layout.drop_item);
//绑定 Adapter到控件
        timeArray .setAdapter(timeAdapter);
        timeArray.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
             //   Toast.makeText(context, "您选择的是："+timeItems[position], Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        back.setOnClickListener(this);
        submit.setOnClickListener(this);

    }

    private void chooseTitle(int flag) {
        String tmp="";
        switch (flag){
            case buyFlag:
                pic.setBackground(getResources().getDrawable(R.mipmap.aim1));
                tmp="购物";break;
            case tripFlag:
                pic.setBackground(getResources().getDrawable(R.mipmap.aim2));
                tmp="旅游";break;
            case saveFlag:
                pic.setBackground(getResources().getDrawable(R.mipmap.aim3));
                tmp="攒第一桶金";break;
            case myAimFlag:
                pic.setBackground(getResources().getDrawable(R.mipmap.aim4));
                tmp="我有自己的规划目标";break;
        }
        title.setText(tmp);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back:
                finish();
                break;
            case R.id.submit:
                Intent intent=new Intent(context,FinishMyAimActivity.class);
                intent.putExtra("type",type);
                intent.putExtra("goods",wantBuy.getText().toString());
                intent.putExtra("money",toBuy.getText().toString());
                intent.putExtra("finish",Integer.valueOf(toBuyDay.getText().toString().trim())/Integer.valueOf(toSavePer.getText().toString().trim()));
                startActivity(intent);
                break;
            default:break;
        }
    }
}
